package nth.bananas.solving;

public class GridSpot<E> {
	
	private int x;
	private int y;
	private E content;
	
	public GridSpot(int x, int y) {
		this(x, y, null);
	}
	
	public GridSpot(int x, int y, E content) {
		this.x = x;
		this.y = y;
		this.content = content;
	}
	
	public int getX() {
		return x;
	}
	
	public int getY() {
		return y;
	}
	
	public E content() {
		return content;
	}
	
	@Override
	public String toString() {
		return String.format("(%d, %d): %s", x, y, content);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((content == null) ? 0 : content.hashCode());
		result = prime * result + x;
		result = prime * result + y;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		GridSpot other = (GridSpot) obj;
		if (content == null) {
			if (other.content != null)
				return false;
		} else if (!content.equals(other.content))
			return false;
		if (x != other.x)
			return false;
		if (y != other.y)
			return false;
		return true;
	}

}
